/**
 * 
 */
package jnzb.control.queue.change;

import jnzb.control.NZBProcessor;
import jnzb.control.events.InfoEventProcessor;
import jnzb.control.uiUpdate.UIUpdateDelegate;
import jnzb.model.nzb.NZB;

/**
 * Performs the neccessary changes to move an nzb down the queue, including
 * waiting for the change to be made
 * 
 * @author AA1
 * 
 */
public class QueueDownChange extends QueueChangeProcessor {

	/**
	 * @param nzbProcessor
	 * @param uiDelegate
	 * @param infoProcessor
	 * @param selectedRow
	 */
	public QueueDownChange(NZBProcessor nzbProcessor,
			UIUpdateDelegate uiDelegate, InfoEventProcessor infoProcessor,
			int selectedRow) {
		super(nzbProcessor, uiDelegate, infoProcessor, selectedRow);
	}

	/**
	 * Returns true if moving this element down will affect the download. i.e,
	 * it's the current download and its not the only one in the queue.
	 * 
	 * @see jnzb.control.queue.change.QueueChangeProcessor#affectsDownload(int)
	 */
	@Override
	public boolean affectsDownload(int selectedRow) {
		return selectedRow == 0 && queueManager.getQueueSize() > 1;
	}

	/**
	 * Will return true if the current downloading NZB is no longer the one that
	 * was moved down. 
	 * 
	 * @see jnzb.control.queue.change.QueueChangeProcessor#checkChangeMade(jnzb.model.nzb.NZB)
	 */
	@Override
	public boolean checkChangeMade(NZB affectedNZB) {
		return !this.nzbProcessor.getCurrentNZB().equals(affectedNZB);
	}

	/**
	 * Moves the NZB down the queue 1 place
	 * 
	 * @see jnzb.control.queue.change.QueueChangeProcessor#makeQueueChange(jnzb.model.nzb.NZB)
	 */
	@Override
	public void makeQueueChange(NZB affectedNZB) {
		int newPos=queueManager.moveDown(affectedNZB);
		if (newPos > -1) {
			uiDelegate.setSelectedQueueEntry(newPos);
		}

	}

}
